﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wutos.Data;
using Wutos.Domain;
using Wutos.Repository;

namespace Wutos.App
{
    public class SportApp
    {
        private Wutos.Domain.ISportRespository service = new SportRepository();

        public List<SportEntity> GetList()
        {
            List<SportEntity> list = new List<SportEntity>();
            list = service.FindList($"select *from sport order by mtime desc");
            return list;
        }
        public List<SportEntity> GetList(string num)
        {
            List <SportEntity> list=new List<SportEntity>();
            list = service.FindList($"select *from sport order by mtime desc limit {num}");
            return list;
        }
        public List<SportEntity> GetList(DateTime dt)
        {
            List<SportEntity> list = new List<SportEntity>();
            string strSql = $"select *from sport where mtime>='{dt.ToString("yyyy-MM-dd")} 00:00:00' and mtime<='{dt.ToString("yyyy-MM-dd")} 23:59:50' order by mtime desc";
            list = service.FindList(strSql);
            return list;
        }

        public List<SportEntity> GetList(DateTime dtStart, DateTime dtEnd)
        {
            List<SportEntity> list = new List<SportEntity>();
            string strSql = $"select *from sport where mtime>='{dtStart.ToString("yyyy-MM-dd")} 00:00:00' and mtime<='{dtEnd.ToString("yyyy-MM-dd")} 23:59:50' order by mtime desc";
            list = service.FindList(strSql);
            return list;
        }




        public int Save(SportEntity entity)
        {
            return service.Insert(entity);
        }

        public int Delete(int id)
        {
            SportEntity entity = service.FindEntity(id);
            if (entity != null) return service.Delete(entity);
            else return 0;
        }
    }
}
